package com.wh.wisdomsite.xbox.server.controller.common;

import com.wh.wisdomsite.xbox.common.util.ResManager;
import com.wh.wisdomsite.xbox.server.util.WebUtil;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletResponse;

/**
 * apiUtilController
 *
 * @version V1.0
 * @Package: com.wh.wisdomsite.xbox.server.controller.common
 * @author: 丁奕
 * @date: 2018-09-20 11:13
 * @Copyright 公司版权所有
 * @Company 贵州万华科技有限公司Copyright (c) 2016
 **/
@Controller
@RequestMapping( value = "/apiUtil")
public class ApiUtilController {

    private static final Log logger = LogFactory.getLog(ApiUtilController.class);

    /**
     * 获取外部接口返回值，解决跨域问题
     * @param url
     * @return
     */
    @RequestMapping( value = "/doGet.do" , method = RequestMethod.GET)
    public void doGet(@RequestParam("url") String url, HttpServletResponse response){
        String result = null;
        try {
            logger.debug("开始调取外部接口，接口url: " + url);
            result = WebUtil.getMessageFromUrl(url);
            logger.debug("调取外部接口结束");
        }catch (Exception e){
            logger.error("调取外部接口异常：" + e.getMessage());
            e.printStackTrace();
        }
        ResManager.getTextOut(response).print(result);
    }
}
